package fr.upstlse.glre.client.espaceperso.panel.west;

import net.mygwt.ui.client.Events;
import net.mygwt.ui.client.Style;
import net.mygwt.ui.client.event.BaseEvent;
import net.mygwt.ui.client.event.Listener;
import net.mygwt.ui.client.widget.TabFolder;
import net.mygwt.ui.client.widget.TabItem;
import net.mygwt.ui.client.widget.layout.BorderLayoutData;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

import fr.upstlse.glre.client.espaceperso.panel.center.CenterPanel;

public class WestPanel {

    private VerticalPanel westPanel;
    private BorderLayoutData westData;
    private Panel navPanel;

    public WestPanel() {
        westPanel = new VerticalPanel();
        westPanel.setTitle("Naviguer sur le site");


        final TabFolder tabFolder = CenterPanel.getCenterPanel();
        tabFolder.setTabWidth(85);  
        tabFolder.addListener(Events.SelectionChange, new Listener() {  
            public void handleEvent(BaseEvent be) {  
                TabItem item = (TabItem) be.item;  
//              Info.show("Selection Changed", "The '{0}' item was selected", item.getText());  
            }  
        });  

        // ajout de l'agenda
        Label agenda = new Label("Agenda");
        agenda.addClickListener(new ClickListener(){
            public void onClick(Widget arg0) {
                TabItem item = new TabItem(Style.CLOSE);  
                item.setText("GWT");  
                item.setIconStyle("icon-tabs");
                item.setId("Agenda");
                tabFolder.add(item);  
                tabFolder.setSelection(item);
                item.setURL("http://www.google.com/calendar/embed?showTitle=0&amp;height=600&amp;wkst=2&amp;hl=fr&amp;bgcolor=%23FFFFFF&amp;src=nmk17icclf9ocn88pf4o0omol4%40group.calendar.google.com&amp;color=%23B1365F");
            }
        });
        addAComponentToNavPanel(agenda);


        // ajout de l'emploi du temps
        Label edt = new Label("EmploiDuTemps");
        edt.addClickListener(new ClickListener(){
            public void onClick(Widget arg0) {
                TabItem item = new TabItem(Style.CLOSE);  
                item.setText("GWT2");
                item.setIconStyle("icon-tabs");
                item.setId("EmploiDuTemps");
                tabFolder.add(item);  
                tabFolder.setSelection(item);

                item.setURL("http://glre2007.googlepages.com/EDT_GLRE_HTML.html");
            }
        });
        addAComponentToNavPanel(edt);

        // ajout du forum
        Label forum = new Label("Forum");
        forum.addClickListener(new ClickListener(){
            public void onClick(Widget sender) {    
                TabItem item = new TabItem(Style.CLOSE);  
                item.setText("Forum");
                item.setIconStyle("icon-tabs");
                item.setId("Forum");
                tabFolder.add(item);  
                tabFolder.setSelection(item);

                item.getContainer().add(new Label("Forum"));
            }
        });
        addAComponentToNavPanel(forum);

//      //ajout de acces au cours
//      Label accesAuCours = new Label("AccesAuCours");
//      accesAuCours.addClickListener(new ClickListener(){
//      public void onClick(Widget sender) {
//      if(centerPanel.getComponent("AccesAuCours")==null){
//      Panel centerPanelAAC = new HTMLPanel();
//      Frame accesAuCours = new Frame("http://www.netool.fr/GLRE/depot/");
//      accesAuCours.setSize("100%", "100%");
//      centerPanelAAC.add(accesAuCours);
//      centerPanelAAC.setId("AccesAuCours");
//      centerPanelAAC.setTitle("AccesAuCours");
//      centerPanelAAC.setAutoScroll(true);
//      centerPanelAAC.setClosable(true);

//      centerPanel.add(centerPanelAAC);
//      centerPanel.activate("AccesAuCours");
//      }
//      else
//      centerPanel.activate("AccesAuCours");
//      } 
//      });
//      addAComponentToNavPanel(accesAuCours);


//      //ajout de acces au cours
//      Label syllabus = new Label("Syllabus");
//      syllabus.addClickListener(new ClickListener(){
//      public void onClick(Widget sender) {
//      if(centerPanel.getComponent("Syllabus")==null){
//      Panel centerPanelSyl = new HTMLPanel();
//      centerPanelSyl.setId("Syllabus");
//      centerPanelSyl.setTitle("Syllabus");
//      centerPanelSyl.setAutoScroll(true);
//      centerPanelSyl.setClosable(true);
//      Frame frame = new Syllabus().getSyllabus();
//      frame.setSize("100%", "100%");
//      centerPanelSyl.add(frame);

//      centerPanel.add(centerPanelSyl);
//      centerPanel.activate("Syllabus");
//      }
//      else
//      centerPanel.activate("Syllabus");
//      } 
//      });
//      addAComponentToNavPanel(syllabus);

//      //ajout du profil
//      Label profil = new Label("Profil");
//      profil.addClickListener(new ClickListener(){
//      public void onClick(Widget sender) {
//      if(centerPanel.getComponent("Profil")==null){
//      Panel centerPanelSyl = new Panel();
//      centerPanelSyl.setId("Profil");
//      centerPanelSyl.setTitle("Profil");
//      centerPanelSyl.setAutoScroll(true);
//      centerPanelSyl.setClosable(true);
//      EditProfil editProfil = new EditProfil();
//      centerPanelSyl.add(editProfil.getPanel());

//      centerPanel.add(centerPanelSyl);
//      centerPanel.activate("Profil");
//      }
//      else
//      centerPanel.activate("Profil");
//      } 
//      });
//      addAComponentToNavPanel(profil);

//      westPanel.add(navPanel);

//      westData = new BorderLayoutData(RegionPosition.WEST);
//      westData.setSplit(true);
//      westData.setMinSize(175);
//      westData.setMaxSize(400);
//      westData.setMargins(new Margins(0, 5, 0, 0));

//      Panel settingsPanel = new Panel();
//      settingsPanel.setHtml("<p>Some settings in here.</p>");
//      settingsPanel.setTitle("Settings");
//      settingsPanel.setBorder(false);
//      settingsPanel.setIconCls("settings-icon");

//      westPanel.add(settingsPanel);
    }

    private void addAComponentToNavPanel(Widget comp){
        westPanel.add(comp);
    }

    public Panel getWestPanel() {
        return westPanel;
    }

    public BorderLayoutData getWestData() {
        return westData;
    }

}
